<?php

/*
	info: 站点设置
	date: 2011-11-27
*/

if (!defined('ADMIN_WEBINROOT'))
{
	header("HTTP/1.0 404 Not Found");
	exit();
}

$webglobal['file_settings'] = array();
//权限分组列表
if ($webglobal['mode'] == 'settings') {
	if (global_CheckSubmit('adminsubmit')) {

		$settingsnew = array();
		
		if (isset($webrequest['settings']['mail'])) {
			$webrequest['settings']['mail']['auth'] = isset($webrequest['settings']['mail']['auth']) ? intval($webrequest['settings']['mail']['auth']) : 1;
			//$webrequest['settings']['mail']['ssl'] = isset($webrequest['settings']['mail']['ssl']) ? intval($webrequest['settings']['mail']['ssl']) : 0;
			//$webrequest['settings']['mail']['mailusername'] = isset($webrequest['settings']['mail']['mailusername']) ? intval($webrequest['settings']['mail']['mailusername']) : 1;

			$settingsnew['mail'] = serialize($webrequest['settings']['mail']);
			unset($webrequest['settings']['mail']);
		}
		
		if (isset($webrequest['settings']['extcredits'])) {
			$webrequest['settings']['extcredits']['user_register'] = isset($webrequest['settings']['extcredits']['user_register']) ? intval($webrequest['settings']['extcredits']['user_register']) : 0;
			$webrequest['settings']['extcredits']['user_comment'] = isset($webrequest['settings']['extcredits']['user_comment']) ? intval($webrequest['settings']['extcredits']['user_comment']) : 0;

			$settingsnew['extcredits'] = serialize($webrequest['settings']['extcredits']);
			unset($webrequest['settings']['extcredits']);
		}
		$webrequest['settings']['siteclosed'] = isset($webrequest['settings']['siteclosed']) ? intval($webrequest['settings']['siteclosed']) : 0;
		$webrequest['settings']['closedreason'] = isset($webrequest['settings']['closedreason']) ? trim($webrequest['settings']['closedreason']) : '';
		$settingsnew = array_merge($webrequest['settings'], $settingsnew);

		foreach ($settingsnew as $key => $val) {
			$db->query("REPLACE INTO {$webconfig['dbpre']}settings (variable, value)
				VALUES ('$key', '$val')");
		}

		include_once WEBFILEPATH.'/include/category.class.php';
		$newsCategoryDataModel = CategoryDataModel::factory('news', array('cache' => true));

		cache_GetSetting(TRUE);
		cache_GetShowIndexNews($newsCategoryDataModel, true);
		cache_GetHotNews($newsCategoryDataModel, true);
		cache_GetHotCoupon(true);
		cache_GetNotice($newsCategoryDataModel, true);

		admin_AddLog("修改站点设置");
		admin_ShowMessage('站点设置修改成功。', ADMIN_WEBURLPATH."/index.php?mode=settings");
	} else {
		$query = $db->query("SELECT * FROM {$webconfig['dbpre']}settings");
		while($setting = $db->FetchArray($query)) {
			$webglobal['file_settings'][$setting['variable']] = $setting['value'];
		}

		if (isset($webglobal['file_settings']['mail']) && $webglobal['file_settings']['mail']) {
			$webglobal['file_settings']['mail'] = unserialize($webglobal['file_settings']['mail']);
		} else {
			$webglobal['file_settings']['mail'] = array();
		}

		if (isset($webglobal['file_settings']['extcredits']) && $webglobal['file_settings']['extcredits']) {
			$webglobal['file_settings']['extcredits'] = unserialize($webglobal['file_settings']['extcredits']);
		} else {
			$webglobal['file_settings']['extcredits'] = array();
		}

		admin_StartFromForm();
	}
}

template_Display('settings', 1);

?>